package com.cxx.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.food.FoodRecipeDto;
import com.cxx.home.dto.food.FoodRecordDto;
import com.cxx.home.dto.food.FoodStatsDto;
import com.cxx.home.dto.food.FoodSummaryDto;
import com.cxx.home.service.FoodService;
import com.cxx.home.vo.FoodQueryVo;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/food")
@Tag(name = "美食记录")
public class FoodController {
    @Resource
    private FoodService foodService;

    @Operation(summary = "新增美食菜谱")
    @PostMapping("/recipe")
    public Boolean addFoodRecipe(@RequestBody @JsonView(WriteView.class) @Validated FoodRecipeDto foodRecipeDto) {
        return foodService.addFoodRecipe(foodRecipeDto);
    }

    @Operation(summary = "更新美食菜谱")
    @PutMapping("/recipe/{id}")
    public Boolean updateFoodRecipe(@PathVariable("id") long id,
                                    @RequestBody @JsonView(WriteView.class) FoodRecipeDto foodRecipeDto) {
        return foodService.updateFoodRecipe(id, foodRecipeDto);
    }

    @Operation(summary = "删除美食菜谱")
    @DeleteMapping("/recipe/{id}")
    public Boolean deleteFoodRecipe(@PathVariable("id") long id) {
        return foodService.deleteFoodRecipe(id);
    }

    @Operation(summary = "分页查询美食菜谱")
    @GetMapping("/recipe/page")
    public IPage<FoodSummaryDto> queryFoodSummary(@RequestParam("currentPage") Integer currentPage,
                                                  @RequestParam("pageSize") Integer pageSize,
                                                  FoodQueryVo foodQueryVo) {
        return foodService.queryFoodSummary(currentPage, pageSize, foodQueryVo);
    }

    @Operation(summary = "查询美食")
    @GetMapping("/recipe/{id}")
    public @JsonView(ReadView.class) FoodRecipeDto queryFoodRecipe(@PathVariable("id") long id) {
        return foodService.queryFoodRecipe(id);
    }

    @Operation(summary = "查询所有美食名称")
    @GetMapping("/recipe/name")
    public List<String> queryFoodName() {
        return foodService.queryFoodName();
    }

    @Operation(summary = "新增美食成果")
    @PostMapping("/record")
    public Boolean addFoodRecord(@RequestBody @JsonView(WriteView.class) @Validated FoodRecordDto foodRecordDto) {
        return foodService.addFoodRecord(foodRecordDto);
    }

    @Operation(summary = "更新美食成果")
    @PutMapping("/record/{id}")
    public Boolean updateFoodRecord(@PathVariable("id") long id,
                                    @RequestBody @JsonView(WriteView.class) FoodRecordDto foodRecordDto) {
        return foodService.updateFoodRecord(id, foodRecordDto);
    }

    @Operation(summary = "删除美食成果")
    @DeleteMapping("/record/{id}")
    public Boolean deleteFoodRecord(@PathVariable("id") long id) {
        return foodService.deleteFoodRecord(id);
    }

    @Operation(summary = "查询美食记录")
    @GetMapping("/record")
    public @JsonView(ReadView.class) List<FoodRecordDto> queryFoodRecord(@RequestParam("startDate") String startDate,
                                                                         @RequestParam("endDate") String endDate) {
        return foodService.queryFoodRecord(startDate, endDate);
    }

    @Operation(summary = "查询美食类别")
    @GetMapping("/category")
    public List<String> queryFoodCategory() {
        return foodService.queryFoodCategory();
    }

    @Operation(summary = "查询美食统计")
    @GetMapping("/stats")
    public FoodStatsDto queryFoodStats() {
        return foodService.queryFoodStats();
    }
}
    